home *** CD-ROM | disk | FTP | other *** search
-
- /*© Copyright 1988-1992 UserLand Software, Inc. All Rights Reserved.*/
-
-
- #include "appletstrings.h"
- #include "appletmenuops.h"
-
-
- boolean pushmenuitem (MenuHandle hmenu, bigstring bs, boolean flenabled) {
-
- short item;
- bigstring bstemp;
-
- item = CountMItems (hmenu) + 1; /*new item will be after current end*/
-
- if (equalstrings (bs, "\p(-")) /*take disabled seperator as is*/
- AppendMenu (hmenu, bs);
-
- else { /*to allow meta-characters in bs, append blank item, then set item text*/
-
- setstringwithchar (chspace, bstemp);
-
- AppendMenu (hmenu, bstemp);
-
- copystring (bs, bstemp); /*work with a copy*/
-
- if (equalstrings (bstemp, "\p-")) /*this is one meta-character that it won't ignore*/
- copystring ("\p\0-", bstemp);
-
- if (!isemptystring (bs))
- SetItem (hmenu, item, bstemp);
- }
-
- if (!flenabled)
- DisableItem (hmenu, item);
-
- return (true);
- } /*pushmenuitem*/
-
-
- void deletemenuitem (MenuHandle hmenu, short ixmenu) {
-
- DelMenuItem (hmenu, ixmenu);
- } /*deletemenuitem*/
-
-
- boolean getmenuitem (MenuHandle hmenu, short ixmenu, bigstring bs) {
-
- if (ixmenu <= 0)
- return (false);
-
- GetItem (hmenu, ixmenu, bs);
-
- return (true);
- } /*getmenuitem*/
-
-
- boolean setmenuitem (MenuHandle hmenu, short ixmenu, bigstring bs) {
-
- SetItem (hmenu, ixmenu, bs);
- } /*setmenuitem*/
-
-
- void checkmenuitem (MenuHandle hmenu, short ixmenu, boolean fl) {
-
- CheckItem (hmenu, ixmenu, fl);
- } /*checkmenuitem*/
-
-
- boolean visitonemenu (short idmenu, tymenuvisitcallback visitproc) {
-
- register MenuHandle hmenu;
- register short i;
- register short lastitem;
-
- hmenu = GetMHandle (idmenu);
-
- if (!hmenu)
- return (false);
-
- lastitem = countmenuitems (hmenu);
-
- for (i = 1; i <= lastitem; i++) {
-
- if (!(*visitproc) (hmenu, i))
- return (false);
- } /*for*/
-
- return (true);
- } /*visitonemenu*/
-
-
- void stylemenuitem (MenuHandle hmenu, short ixmenu, short style) {
-
- SetItemStyle (hmenu, ixmenu, style);
- } /*stylemenuitem*/
-
-
- void installmenu (short idmenu, MenuHandle *hmenu) {
-
- *hmenu = GetMenu (idmenu);
-
- if (*hmenu != nil) /*defensive driving*/
- InsertMenu (*hmenu, 0);
- } /*installmenu*/
-
-
- void installhierarchicmenu (short idmenu, MenuHandle *hmenu) {
-
- *hmenu = GetMenu (idmenu);
-
- if (*hmenu != nil)
- InsertMenu (*hmenu, -1);
- } /*installhierarchicmenu*/
-
-
- void setmenuitemenable (hmenu, item, fl) MenuHandle hmenu; short item; boolean fl; {
-
- /*
- enable or disable a menu or a menu item. if fl is true we enable the item,
- if false we disable it.
-
- if item == 0 we enable or disable the entire menu.
-
- dmb 8/1/90: check for dummy items (negative item numbers)
- */
-
- if (item < 0) /*this item has been dummied out -- do nothing*/
- return;
-
- if (fl)
- EnableItem (hmenu, item);
- else
- DisableItem (hmenu, item);
-
- if (item == 0)
- DrawMenuBar ();
- } /*setmenuitemenable*/
-
-
- void disablemenuitem (hmenu, item) MenuHandle hmenu; short item; {
-
- setmenuitemenable (hmenu, item, false);
- } /*disablemenuitem*/
-
-
- void enablemenuitem (hmenu, item) MenuHandle hmenu; short item; {
-
- setmenuitemenable (hmenu, item, true);
- } /*enablemenuitem*/
-
-
- short countmenuitems (MenuHandle hmenu) {
-
- return (CountMItems (hmenu));
- } /*countmenuitems*/
-
-
- void uncheckallmenuitems (MenuHandle hmenu) {
-
- register short i;
- register short ct;
-
- ct = countmenuitems (hmenu);
-
- for (i = 1; i <= ct; i++)
- CheckItem (hmenu, i, false);
- } /*uncheckallmenuitems*/
-
-
- void disableallmenuitems (MenuHandle hmenu) {
-
- register short i;
- register short ct;
-
- ct = countmenuitems (hmenu);
-
- for (i = 1; i <= ct; i++)
- setmenuitemenable (hmenu, i, false);
- } /*disableallmenuitems*/
-
-
- void enableallmenuitems (MenuHandle hmenu) {
-
- register short i;
- register short ct;
-
- ct = countmenuitems (hmenu);
-
- for (i = 1; i <= ct; i++)
- setmenuitemenable (hmenu, i, true);
- } /*enableallmenuitems*/
-
-
- void disableemptymenuitems (MenuHandle hmenu) {
-
- short i, j;
- short ctmenuitems;
-
- ctmenuitems = countmenuitems (hmenu);
-
- for (i = 1; i <= ctmenuitems; i++) {
-
- boolean flnotempty = false;
- bigstring bs;
-
- getmenuitem (hmenu, i, bs);
-
- for (j = 1; j <= stringlength (bs); j++) {
-
- if (bs [j] != ' ') {
-
- flnotempty = true;
-
- break;
- }
- } /*for*/
-
- setmenuitemenable (hmenu, i, flnotempty);
- } /*for*/
- } /*disableemptymenuitems*/
-
-
-